package com.ourteam.product.model.dao.impl;

import com.ourteam.product.model.dao.IProductModelServiceParameterDAO;
import com.ourteam.product.model.dao.ProductModelServiceParameter;
import com.ourteam.product.model.dao.ProductModelServiceParameterDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 IRKT 2017
 * Auto Generate Date : 2017-11-17 11:01:17
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductModelServiceParameterDAOJdbcImpl
    extends AbstractSpringDAO implements IProductModelServiceParameterDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ServiceId, ParameterCode, ParameterName, ParameterType,
            DataTypeId, DataCheck, IsArray, SortIndex, Status, Remarks, DataType
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ServiceId,
            _DataObjectProperty.ParameterCode, _DataObjectProperty.ParameterName,
            _DataObjectProperty.ParameterType, _DataObjectProperty.DataTypeId,
            _DataObjectProperty.DataCheck, _DataObjectProperty.IsArray,
            _DataObjectProperty.SortIndex, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks, _DataObjectProperty.DataType
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductModelServiceParameter, ProductModelServiceParameterDAOQueryBean> daoHelper;

    public AbstractProductModelServiceParameterDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductModelServiceParameter, ProductModelServiceParameterDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.product.model.dao.IProductModelObjectDAO.EntityName)
                                .append(" PRODUCT_MODEL_OBJECT ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.product.model.dao.IProductModelObjectDAO.Id,
                    com.ourteam.product.model.dao.IProductModelObjectDAO.EntityName +
                    ".", "PRODUCT_MODEL_OBJECT."));
            relatedJoinSQLBuffer.append(" = ").append(DataTypeId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductModelServiceParameter
         * @throws Exception
         */
    public boolean checkIsUnique(
        ProductModelServiceParameter aProductModelServiceParameter)
        throws Exception {
        if (aProductModelServiceParameter == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductModelServiceParameter.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductModelServiceParameter
     * @throws Exception
     */
    public void insert(
        ProductModelServiceParameter aProductModelServiceParameter)
        throws Exception {
        super.doInsert(aProductModelServiceParameter);
    }

    /**
         * Batch Insert Datas
         * @param aProductModelServiceParameter
         * @throws Exception
         */
    public void batchInsert(
        ProductModelServiceParameter[] aProductModelServiceParameters)
        throws Exception {
        super.doBatchInsert(aProductModelServiceParameters);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductModelServiceParameterDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(
        ProductModelServiceParameter aProductModelServiceParameter)
        throws Exception {
        delete(aProductModelServiceParameter.getId());
    }

    /**
     * Update Data Selective
     * @param aProductModelServiceParameter
     * @throws Exception
     */
    public void update(
        ProductModelServiceParameter aProductModelServiceParameter)
        throws Exception {
        if (aProductModelServiceParameter.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductModelServiceParameter);

        ProductModelServiceParameter tempObj = findById(aProductModelServiceParameter.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductModelServiceParameter, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductModelServiceParameters[]
     * @throws Exception
     */
    public void batchUpdate(
        ProductModelServiceParameter[] aProductModelServiceParameters)
        throws Exception {
        super.doBatchUpdate(aProductModelServiceParameters);
    }

    /**
         * Update Data By Condictions
         * @param aProductModelServiceParameter
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(
        ProductModelServiceParameter aProductModelServiceParameter,
        ProductModelServiceParameterDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aProductModelServiceParameter, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductModelServiceParameterDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(
        ProductModelServiceParameter aProductModelServiceParameter)
        throws Exception {
        if (aProductModelServiceParameter.getParameterCode() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.parameterCode value is not allow NULL");
        }

        if (aProductModelServiceParameter.getParameterName() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.parameterName value is not allow NULL");
        }

        if (aProductModelServiceParameter.getParameterType() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.parameterType value is not allow NULL");
        }

        if (aProductModelServiceParameter.getDataCheck() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.dataCheck value is not allow NULL");
        }

        if (aProductModelServiceParameter.getIsArray() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.isArray value is not allow NULL");
        }

        if (aProductModelServiceParameter.getStatus() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.status value is not allow NULL");
        }

        if (aProductModelServiceParameter.getRemarks() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.remarks value is not allow NULL");
        }

        if (aProductModelServiceParameter.getDataType() == null) {
            throw new Exception(
                "The ProductModelServiceParameter.dataType value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductModelServiceParameter findById(final long id)
        throws Exception {
        ProductModelServiceParameterDAOQueryBean queryBean = new ProductModelServiceParameterDAOQueryBean();

        ProductModelServiceParameterDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductModelServiceParameter[] ProductModelServiceParameters = query(queryBean);

        if (ProductModelServiceParameters.length == 0) {
            return null;
        } else {
            return ProductModelServiceParameters[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductModelServiceParameter[]
         * @throws Exception
         */
    public ProductModelServiceParameter[] query(
        ProductModelServiceParameterDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductModelServiceParameterRowMapper());

        return (ProductModelServiceParameter[]) result.toArray(new ProductModelServiceParameter[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductModelServiceParameterDAOQueryBean queryBean)
        throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductModelServiceParameterDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(
        ProductModelServiceParameter[] aProductModelServiceParameters,
        ProductModelServiceParameterDAOQueryBean queryBean)
        throws Exception {
        daoHelper.synchronize(aProductModelServiceParameters, queryBean);
    }

    public void synchronize(
        ProductModelServiceParameter[] aProductModelServiceParameters,
        ProductModelServiceParameterDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductModelServiceParameter> callBack)
        throws Exception {
        daoHelper.synchronize(aProductModelServiceParameters, queryBean,
            callBack);
    }

    public static class JdbcProductModelServiceParameterRowMapper
        implements RowMapper<ProductModelServiceParameter> {
        public ProductModelServiceParameter mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductModelServiceParameter object = new ProductModelServiceParameter();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object serviceId = null;

                serviceId = resultSet.getObject(columnIndex++);

                object.setServiceIdNull(resultSet.getBoolean(columnIndex++));

                if (serviceId != null) {
                    setBeanValue(object, _DataObjectProperty.ServiceId,
                        serviceId);
                }

                Object parameterCode = null;

                parameterCode = resultSet.getObject(columnIndex++);

                object.setParameterCodeNull(resultSet.getBoolean(columnIndex++));

                if (parameterCode != null) {
                    setBeanValue(object, _DataObjectProperty.ParameterCode,
                        parameterCode);
                }

                Object parameterName = null;

                parameterName = resultSet.getObject(columnIndex++);

                object.setParameterNameNull(resultSet.getBoolean(columnIndex++));

                if (parameterName != null) {
                    setBeanValue(object, _DataObjectProperty.ParameterName,
                        parameterName);
                }

                Object parameterType = null;

                parameterType = resultSet.getObject(columnIndex++);

                object.setParameterTypeNull(resultSet.getBoolean(columnIndex++));

                if (parameterType != null) {
                    setBeanValue(object, _DataObjectProperty.ParameterType,
                        parameterType);
                }

                Object dataTypeId = null;

                dataTypeId = resultSet.getObject(columnIndex++);

                object.setDataTypeIdNull(resultSet.getBoolean(columnIndex++));

                if (dataTypeId != null) {
                    setBeanValue(object, _DataObjectProperty.DataTypeId,
                        dataTypeId);
                }

                Object dataCheck = null;

                dataCheck = resultSet.getObject(columnIndex++);

                object.setDataCheckNull(resultSet.getBoolean(columnIndex++));

                if (dataCheck != null) {
                    setBeanValue(object, _DataObjectProperty.DataCheck,
                        dataCheck);
                }

                Object isArray = null;

                isArray = resultSet.getObject(columnIndex++);

                object.setIsArrayNull(resultSet.getBoolean(columnIndex++));

                if (isArray != null) {
                    setBeanValue(object, _DataObjectProperty.IsArray, isArray);
                }

                Object sortIndex = null;

                sortIndex = resultSet.getObject(columnIndex++);

                object.setSortIndexNull(resultSet.getBoolean(columnIndex++));

                if (sortIndex != null) {
                    setBeanValue(object, _DataObjectProperty.SortIndex,
                        sortIndex);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object dataType = null;

                dataType = resultSet.getObject(columnIndex++);

                object.setDataTypeNull(resultSet.getBoolean(columnIndex++));

                if (dataType != null) {
                    setBeanValue(object, _DataObjectProperty.DataType, dataType);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
